package redis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.Test;

import redis.clients.jedis.Jedis;

public class TestSortSet {
	static Jedis jedis = null;

    static {
        jedis = new Jedis("192.168.79.131", 6379);//redis服务器地址与端口号
        jedis.auth("211125");    }
    
    // 测试Java做为客户端连接redis
    public static void main(String[] args) {
    	System.out.println("服务启动..."+jedis.ping());
    	jedis.flushDB();
    }
    
    // 7.5.7 操作有序集合
    @Test
    public void zaddTest() {
    	Map<String,Double> map = new HashMap<String,Double>();
    	map.put("news_001", 300.0);
    	map.put("news_002", 400.0);
    	map.put("news_003", 200.0);
    	Long result = jedis.zadd("news", map);
    	System.out.println(result);
    }
    
    @Test
    public void zrangeTest() {
    	List<String> score = jedis.zrange("score",0,-1);
    	System.out.println(score);
    }
    @Test
    public void zScorerangeTest() {
        List<String> score = jedis.zrangeByScore("news",100,300);
        System.out.println(score);
    }
    
    @Test
    public void zcardTest() {
    	Long num = jedis.zcard("news");
    	System.out.println(num);
    }
    
    @Test
    public void zcountTest() {
    	Long num = jedis.zcount("score",2,4);
    	System.out.println(num);
    }
    
    @Test
    public void zscoreTest() {
    	Double zscore = jedis.zscore("news","news_001");
    	System.out.println(zscore);
    }
    
    @Test
    public void zremTest() {
    	Long result = jedis.zrem("news","news_001");
    	System.out.println(result);
    }
}
